package moriarty.gwt.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.Label;

public class SubmissionTab extends Composite{

	private Grid gridLayout;
	private Button sendButton;
	private Label title;
	private SubmissionWidget submissionWidget;
	private SubmissionDialog submissionDialog;
	
	public SubmissionTab(){
		gridLayout = new Grid(3, 3);

		title = new Label("Song of the Day");
		title.addStyleName("title");
		
		//Send button
		sendButton = new Button("Send");
		sendButton.addStyleName("sendButton");
		
		//Custom Widget for SOTD submission - Thanks Cameron!
		submissionWidget = new SubmissionWidget();
		
		//Add components to panels and add panel to the root.
		gridLayout.setWidget(0, 1, title);
		gridLayout.setWidget(1, 1, submissionWidget);
		gridLayout.setWidget(1, 2, sendButton);

		//Create the Submission Dialog that appears after the Send Button is clicked
		submissionDialog = new SubmissionDialog();

		// Add a handler to close the DialogBox
		submissionDialog.getCloseButton().addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				submissionDialog.getDialogBox().hide();
				sendButton.setEnabled(true);
				sendButton.setFocus(true);
			}
		});

		// Add a handler to send the name to the server
		SubmissionHandler submissionHandler = new SubmissionHandler(this, submissionDialog);
		sendButton.addClickHandler(submissionHandler);
		initWidget(gridLayout);
	}

	public Grid getGridLayout() {
		return gridLayout;
	}

	public Button getSendButton() {
		return sendButton;
	}

	public SubmissionWidget getSubmissionWidget() {
		return submissionWidget;
	}
	
}
